package com.wqiuqiu.gulimall.product.web;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.wqiuqiu.common.constant.ProductConstant;
import com.wqiuqiu.gulimall.product.entity.CategoryEntity;
import com.wqiuqiu.gulimall.product.service.CategoryService;
import com.wqiuqiu.gulimall.product.vo.Catelog2Vo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;


@Slf4j
@Controller
public class IndexControler {

    @Autowired
    CategoryService categoryService;



    @GetMapping({"/","/index.html"})
    public String IndexPage(Model model){
        //得到所有的一级分类
        List<CategoryEntity> categoryEntities = categoryService.getAllFristCatelog();
        model.addAttribute("categorys",categoryEntities);
        return "index";
    }
    @ResponseBody
    @GetMapping("/index/json/catalog.json")
    public Map<String, List<Catelog2Vo>> CatelogJson(){
        Map<String, List<Catelog2Vo>> map = categoryService.getCatelog();
        return map;
    }



}
